//
//  CTCommentViewController.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/15.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTCommentViewController.h"
#import "CTTabBarController.h"
#import "CTLoginViewController.h"
#import "CTUserViewController.h"
//header
#import "CTHeader.h"

//view
#import "CTCommentView.h"

//logic
#import "CTLogic.h"

//func
#import "CTDebugManager.h"
#import "CTGenRequestData.h"
#import "CTDataGenerator.h"
#import "CTRemindView.h"
#import "CTAppLanguage.h"
#import "CTActivitorView.h"
#import "CTShareView.h"
#import "CTShare.h"
#import "CTRequestUtil.h"
#import "CTMoreView.h"
#import "CTLogin.h"
#import "CTTextManager.h"
#import "CTImageProcessing.h"
#import "MobClick.h"
#import "CTImageProcessing.h"

//model
#import "CTHomePageItems.h"
#import "CTLogicItems.h"
#import "CTShareItem.h"

//tool
#import "UIImageView+MJWebCache.h"
#import "MJPhotoBrowser.h"
#import "MJPhoto.h"


static commentFlipNumber = 0;

typedef enum{
    ReportTypeReport = 1,
    ReportTypeDelete
}ReportType;

@interface CTCommentViewController ()<CTCommentViewDelegate,CTShareViewDelegate,CTMoreViewDelegate,UIAlertViewDelegate>
{
    CTCommentView * commentView;
    CTActivitorView * acView;
    CTLogic * logic;
    
    CTShareView * shareView;
    CTComment * commentItem;
    
    ReportType reportType;
    
    CTFollowList * currentFollowListItem;
    
    UIImage     *shareImage;
    
}
@end

@implementation CTCommentViewController
@synthesize followListItem,levelType,scheme_id;

- (void)dealloc
{
    currentFollowListItem = nil;
    
    [commentView removeFromSuperview];
    commentView = nil;
    
    scheme_id = nil;
    
    [acView removeFromSuperview];
    acView = nil;
    
    [shareView removeFromSuperview];
    shareView.delegate = self;
    shareView = nil;
    
    followListItem = nil;
    logic = nil;
    
    commentItem = nil;
    
    shareImage = nil;
    
//    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_PUBLISH_COMMENT_SUCCESS object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_DELETE_COMMENT_SUCCESS object:nil];
    
    [CTDebugManager showDebugLogInfo:@"dealloc : CTCommentViewController Is Removed!!!"];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        logic = [[CTLogic alloc] init];
        
//        //发布评论成功
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(publishCommentSuccessed:) name:CT_NOTI_PUBLISH_COMMENT_SUCCESS object:nil];
        //删除评论成功
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteCommentSuccessed:) name:CT_NOTI_DELETE_COMMENT_SUCCESS object:nil];
    }
    return self;
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    [commentView reloadData];

    //统计
    [MobClick beginLogPageView:@"CTCommentViewController"];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    //统计
    [MobClick endLogPageView:@"CTCommentViewController"];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    commentView = [[CTCommentView alloc] init];
    commentView.delegate = self;
    commentView.followListItem = followListItem;
    [self.view addSubview:commentView];
    
    if (followListItem == nil) {
        [self sendPublishDetailsInfoRequest:scheme_id];
        [commentView refresh];
    }else{
        scheme_id = followListItem.scheme_id;
        [commentView refresh];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark - request -

-(void)sendPublishDetailsInfoRequest:(NSString *)schemeID
{
    [logic getPublishDetailsInfoRequest:[CTGenRequestData genRequestPublishDetailsInfoItem:schemeID] successCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            
            commentView.followListItem = [CTDataGenerator generatePublishDetailsInfo];
            [commentView reloadData];
            
            commentFlipNumber = 1;
            [self sendCommentListRequest];
        });
    } failedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [commentView refreshPullDownEnd];
        });
    }];
}

-(void)sendCommentListRequest
{
    [logic commentListRequest:[CTGenRequestData genRequestCommentListItems:scheme_id withFlipNumber:commentFlipNumber] successCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            
            commentView.commentListArray = [CTDataGenerator generateCommentListItems];
            
            [commentView refreshPullDownEnd];
            
        });
    } failedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
       
            [commentView refreshPullDownEnd];
           
        });
    }];
}

-(void)sendComentDeleteRequest
{
    acView = [[CTActivitorView alloc] init];
    [acView showActivitorViewOn:self.view withType:CTActivitorViewLongShadow];
   
    
    [logic cancelCommentRequest:[CTGenRequestData genRequestCancelCommentItem:commentItem.comment_id] successCompletionHandler:^{
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_DELETE_COMMENT_SUCCESS object:nil];
            
            [acView removeActivitorView];
            acView = nil;
            
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"commentView_delete_comment_success" withValue:nil withTable:@"Language"]];
        });
        
    } failedHandler:^{
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [acView removeActivitorView];
            acView = nil;
            
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"commentView_delete_comment_failed" withValue:nil withTable:@"Language"]];
        });
    }];
}


-(void)sendCommentRequestWithContent:(NSString *)text
{
    acView = [[CTActivitorView alloc] init];
    [acView showActivitorViewOn:self.view withType:CTActivitorViewLongShadow];
    
    [logic commentRequest:[CTGenRequestData genRequestCommentItem:scheme_id withContent:text] successCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            
            
            [self performSelector:@selector(publishCommentSuccessed:) withObject:nil afterDelay:1.0];
            
            
            [acView removeActivitorView];
            acView = nil;
            
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
            
        });
    } failedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [acView removeActivitorView];
            acView = nil;
            
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });
    }];
}




#pragma mark - comment view delegate -

-(void)refreshControlPullDown:(CTCommentView *)view
{
    [self sendPublishDetailsInfoRequest:scheme_id];
}
-(void)refreshControlPullUp:(CTCommentView *)view
{
    commentFlipNumber ++;
    [self sendCommentListRequest];
}



- (void)commentViewBackBtnAction:(CTCommentView *) view
{
    if (levelType == CTCommentViewControllerLevelsFirst) {
     
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC showTabbarWithAnimate:YES];
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)commentViewSendBtnAction:(CTCommentView *)view withText:(NSString *)textStr
{
    [self sendCommentRequestWithContent:textStr];
}
- (void)commentViewHitAttentionBtnAction:(CTCommentView *)view WithItem:(CTFollowList *)item withBool:(BOOL)attentionBool
{
    if (attentionBool == YES) {
        [logic followPersonRequest:[CTGenRequestData genRequestFollowPseronItem:item.user.uid] successCompletionHandler:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [CTDebugManager showDebugLogInfo:@"关注成功！"];
                  [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_FOLLOWING_SUCCESS object:nil];
            });
        } failedHandler:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [CTDebugManager showErrorLogInfo:@"关注失败！"];
            });
        }];
    }else{
        
        [logic cancelFollowPersonRequest:[CTGenRequestData genRequestCancelFollowPseronItem:item.user.uid] successCompletionHandler:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [CTDebugManager showDebugLogInfo:@"取消关注成功！"];
                [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_CANCEL_FOLLOWING_SUCCESS object:nil];
            });
        } failedHandler:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [CTDebugManager showErrorLogInfo:@"取消关注失败！"];
            });
        }];
    }
}
- (void)commentViewHitHeadAction:(CTCommentView *)view withItem:(CTFollowList *)item
{
    
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        CTUserViewController * userVC = [[CTUserViewController alloc] init];
        userVC.pushType = CTUserViewControllerPushFromTypeOther;
        userVC.levelType = CTUserViewControllerLevelOther;
        userVC.userUid = item.user.uid;
        [self.navigationController pushViewController:userVC animated:YES];
        
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
    
}
- (void)commentViewHitPicImageBtnAction:(CTCommentView *)view withItem:(CTFollowList *)item withImageView:(UIImageView *)picimageView
{
    if ([[CTTextManager shareInstance] isBlankString:item.pic_url]) return;
    
    NSMutableArray * photos = [NSMutableArray arrayWithObjects:0, nil];
    MJPhoto *photo = [[MJPhoto alloc] init];
    photo.image = [CTRequestUtil requestImageWithUrl:item.pic_url]; // 图片路径
    photo.srcImageView = picimageView;
    [photos addObject:photo];
    
 //   if (photo.image == nil) return;
    // 2.显示相册
    MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
    browser.photos = photos; // 设置所有的图片
    [browser show];
    photos = nil;
    
}
- (void)commentViewHitFavourBtnAction:(CTCommentView *)view withItem:(CTFollowList *) item withBool:(BOOL)favBtnBool
{
    if (favBtnBool == YES) {
        [logic likePersonRequest:[CTGenRequestData genRequestLikePseronItem:item.scheme_id] successCompletionHandler:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [CTDebugManager showDebugLogInfo:@"点赞成功！"];
                [self performSelector:@selector(likePersonSucceed:) withObject:nil afterDelay:1.0];
            });
        } failedHandler:^{
            [CTDebugManager showErrorLogInfo:@"点赞失败！"];
        }];
    }else{
        [logic cancelLikePersonRequest:[CTGenRequestData genRequestCancelLikePseronItem:item.scheme_id] successCompletionHandler:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [CTDebugManager showDebugLogInfo:@"取消点赞成功！"];
                [self performSelector:@selector(cancelLikePersonSucceed:) withObject:nil afterDelay:1.0];
                
            });
        } failedHandler:^{
            [CTDebugManager showErrorLogInfo:@"取消点赞失败！"];
        }];
    }
}

- (void)commentViewHitShareBtnAction:(CTCommentView *)view withItem:(CTFollowList *)item withImage:(UIImage *)img
{
    shareImage = img;
    //share view
    
    shareView = [[CTShareView alloc] init];
    shareView.delegate = self;
    [shareView showShareViewOn:self.view.window withShareViewType:CTShareViewTypeDefault];
}
- (void)commentViewHitMoreBtnAction:(CTCommentView *)view withItem:(CTFollowList *)item
{
    currentFollowListItem = item;
    
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        CTUserItem * userItem = [CTUser userInfo];
        if ([item.user.uid isEqualToString:userItem.uid]) {
            CTMoreView * moreView = [[CTMoreView alloc] init];
            moreView.delegate = self;
            [moreView showMoreViewOn:self.view.window withMoreViewType:CTMoreViewTypeDefault];
        }else{
            CTMoreView * moreView = [[CTMoreView alloc] init];
            moreView.delegate = self;
            [moreView showMoreViewOn:self.view.window withMoreViewType:CTMoreViewTypeReport];
        }
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
- (void)commentViewHitFavBtnHeadAction:(CTCommentView *)view withItem:(CTListDetailUser *)item
{
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        CTUserViewController * userVC = [[CTUserViewController alloc] init];
        userVC.pushType = CTUserViewControllerPushFromTypeOther;
        userVC.levelType = CTUserViewControllerLevelOther;
        userVC.userUid = item.uid;
        [self.navigationController pushViewController:userVC animated:YES];
        
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}

-(void)commentViewDeleteCommentAction:(CTCommentView *)view withItem:(CTFollowList *)item withCommentUser:(CTCommentListItems *)commentUser
{
    commentItem = commentUser.commentItem;
    
    
    [self sendComentDeleteRequest];
}

- (void)commentViewHitTopicAction:(CTCommentView *)view withItem:(CTTopic *)item
{
     [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_JUMP_TO_GROUP object:item];
    
    [self.navigationController popViewControllerAnimated:YES];
    
    CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
    [tabbarVC showTabbarWithAnimate:YES];
    [tabbarVC selectTabbarIndex:0];
    
    
}
- (void)commentViewHitHeadBtnAction:(CTCommentView *) view withItem:(CTCommentListItems *)item
{
    CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
    [tabbarVC hideTabbarWithAnimate:YES];
    CTUserViewController * userVC = [[CTUserViewController alloc] init];
    userVC.pushType = CTUserViewControllerPushFromTypeOther;
    userVC.levelType = CTUserViewControllerLevelOther;
    userVC.userUid = item.commentItem.user.uid;
    [self.navigationController pushViewController:userVC animated:YES];
}




#pragma mark - share view delegate -

//试图移除
-(void)viewDidRemoved:(CTShareView *)view
{
    shareView = nil;
    shareView.delegate = nil;
}
//分享到微信朋友圈
- (void)shareViewShareToWechatFriends:(CTShareView *) view withImage:(UIImage *)image
{
    
    CTShareItem * shareItem = [[CTShareItem alloc] init];
    shareItem.img = shareImage;// [CTRequestUtil requestImageWithUrl:followListItem.thumb_url];
    shareItem.content = followListItem.text;
    shareItem.defaultContent = followListItem.text;
    shareItem.url = followListItem.share_url;
    shareItem.descr = [CTAppLanguage localizedStringForKey:@"share_topic_describe" withValue:nil withTable:@"Language"];;
    shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
    
    
    [CTShare shareItem:shareItem shareChannel:CTShareChannelWechatFriend publishType:CTPublishTypeNews shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });
    }];
}
//分享到QQ空间
- (void)shareViewShareToQQSpace:(CTShareView *)view withImage:(UIImage *)image
{
    CTShareItem * shareItem = [[CTShareItem alloc] init];
    UIImage *img = shareImage;// [CTRequestUtil requestImageWithUrl:followListItem.thumb_url];
    CGSize size = CGSizeMake(320, 320);
    shareItem.img = [CTImageProcessing imageCompressionImg:img WithSize:size];
    shareItem.content = followListItem.text;
    shareItem.defaultContent = followListItem.text;
    shareItem.url = followListItem.share_url;
    shareItem.descr = [CTAppLanguage localizedStringForKey:@"share_pic_describe" withValue:nil withTable:@"Language"];
    shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
    
    [CTShare shareItem:shareItem shareChannel:CTShareChannelQQSpace publishType:CTPublishTypeImage shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });
    }];
}
//分享到新浪微博
- (void)shareViewShareToSina:(CTShareView *)view withImage:(UIImage *)image
{
//    NSLog(@"share = %@",shareImage);
    CTShareItem * shareItem = [[CTShareItem alloc] init];
//    UIImage *img = [CTImageProcessing imageCompressionImg:shareImage WithSize:CGSizeMake(100, 100)];
    shareItem.img =  shareImage;//[CTRequestUtil requestImageWithUrl:followListItem.thumb_url];
    shareItem.content = followListItem.text;
    shareItem.defaultContent = followListItem.text;
    shareItem.url   = followListItem.share_url;
    shareItem.descr = [CTAppLanguage localizedStringForKey:@"share_pic_describe" withValue:nil withTable:@"Language"];;
    shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
    
    [CTShare sinaBtnAction:shareItem shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });

    }];
//    [CTShare shareItem:shareItem shareChannel:CTShareChannelSina publishType:CTPublishTypeImage shareSuccessHandler:^{
//        dispatch_async(dispatch_get_main_queue(), ^{
//            CTRemindView * remindView = [[CTRemindView alloc] init];
//            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
//        });
//    } shareFailedHandler:^{
//        dispatch_async(dispatch_get_main_queue(), ^{
//            CTRemindView * remindView = [[CTRemindView alloc] init];
//            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
//        });
//    }];
}
//分享到微信
- (void)shareViewShareToWeChat:(CTShareView *)view withImage:(UIImage *)image
{
    CTShareItem * shareItem = [[CTShareItem alloc] init];
    shareItem.img = shareImage;//[CTRequestUtil requestImageWithUrl:followListItem.thumb_url];
    shareItem.defaultContent = followListItem.text;
    shareItem.descr = followListItem.text;
    shareItem.url   = followListItem.share_url;
    shareItem.content = [CTAppLanguage localizedStringForKey:@"share_pic_describe" withValue:nil withTable:@"Language"];;
    shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
    
    [CTShare shareItem:shareItem shareChannel:CTShareChannelWechat publishType:CTPublishTypeNews shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });
    }];
}
//分享到QQ
- (void)shareViewShareToQQ:(CTShareView *)view withImage:(UIImage *)image
{
    
    CTShareItem * shareItem = [[CTShareItem alloc] init];
    UIImage * img = shareImage;//[CTRequestUtil requestImageWithUrl:followListItem.thumb_url];
    CGSize size = CGSizeMake(320, 320);
    shareItem.img = [CTImageProcessing imageCompressionImg:img WithSize:size];
    shareItem.defaultContent = followListItem.text;
    shareItem.descr = followListItem.text;
    shareItem.url   = followListItem.share_url;
    shareItem.content = [CTAppLanguage localizedStringForKey:@"share_pic_describe" withValue:nil withTable:@"Language"];
    shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
    
    
    [CTShare shareItem:shareItem shareChannel:CTShareChannelQQ publishType:CTPublishTypeNews shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });
    }];
}



#pragma mark - more view delegate -

- (void)moreViewDelBtnAction:(CTMoreView *)view
{
    reportType = ReportTypeDelete;
    
    NSString * titleStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Remind" withValue:nil withTable:@"Language"];
    NSString * messageStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Message_Delete" withValue:nil withTable:@"Language"];
    NSString * confirmStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Confirm" withValue:nil withTable:@"Language"];
    NSString * cancelStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Cancel" withValue:nil withTable:@"Language"];
    
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:titleStr message:messageStr delegate:self cancelButtonTitle:cancelStr otherButtonTitles:confirmStr, nil];
    [alertView show];
    
    view = nil;
}
- (void)moreViewreportBtnAction:(CTMoreView *)view
{
    reportType = ReportTypeReport;
    
    NSString * titleStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Remind" withValue:nil withTable:@"Language"];
    NSString * messageStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Message_Report" withValue:nil withTable:@"Language"];
    NSString * confirmStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Confirm" withValue:nil withTable:@"Language"];
    NSString * cancelStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Cancel" withValue:nil withTable:@"Language"];
    
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:titleStr message:messageStr delegate:self cancelButtonTitle:cancelStr otherButtonTitles:confirmStr, nil];
    [alertView show];
    
    view = nil;
}
- (void)moreViewCanacelBtnAction:(CTMoreView *)view
{
    
    view = nil;
}
- (void)moreViewDidRemoved:(CTMoreView *)view
{
    view = nil;
}

#pragma mark - alert view delegate -

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    if (buttonIndex == 1) {
        if (reportType == ReportTypeReport) {
            //举报
            acView = [[CTActivitorView alloc] init];
            [acView showActivitorViewOn:self.view withType:CTActivitorViewDefault];
            
            [logic reportRequest:[CTGenRequestData genRequestReportItem:currentFollowListItem.scheme_id] successCompletionHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [acView removeActivitorView];
                    acView = nil;
                    
                    CTRemindView * remindView = [[CTRemindView alloc] init];
                    [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Report_Success" withValue:nil withTable:@"Language"]];
                    
                });
            } failedHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [acView removeActivitorView];
                    acView = nil;
                    
                    CTRemindView * remindView = [[CTRemindView alloc] init];
                    [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Report_Failed" withValue:nil withTable:@"Language"]];
                    
                });
            }];
        }else{
            //删除自己的发布内容
            
            acView = [[CTActivitorView alloc] init];
            [acView showActivitorViewOn:self.view withType:CTActivitorViewDefault];
            
            [logic deletePublishRequest:[CTGenRequestData genRequestDeletePublishItem:currentFollowListItem.scheme_id] successCompletionHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_DELETE_PUBLISH_SUCCESS object:nil];
                    
                    [acView removeActivitorView];
                    acView = nil;
                    
                    CTRemindView * remindView = [[CTRemindView alloc] init];
                    [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Delete_Success" withValue:nil withTable:@"Language"]];
                    
                    if (levelType == CTCommentViewControllerLevelsFirst) {
                        
                        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
                        [tabbarVC showTabbarWithAnimate:YES];
                    }
                    
                    [self.navigationController popViewControllerAnimated:YES];
                    
                });
            } failedHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [acView removeActivitorView];
                    acView = nil;
                    
                    CTRemindView * remindView = [[CTRemindView alloc] init];
                    [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Delete_Failed" withValue:nil withTable:@"Language"]];
                    
                });
            }];
            
        }
    }
    
    alertView.delegate = nil;
    [alertView removeFromSuperview];
    alertView = nil;
}






#pragma mark - notification -

-(void)publishCommentSuccessed:(id)sender
{
    commentFlipNumber = 1;
    [self sendCommentListRequest];
 
    
    [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_PUBLISH_COMMENT_SUCCESS object:nil];
}

-(void)deleteCommentSuccessed:(id)sender
{
    commentFlipNumber = 1;
    [self sendCommentListRequest];
}

-(void)likePersonSucceed:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_LIKE_SUCCESS object:nil];
}

-(void)cancelLikePersonSucceed:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_CANCEL_LIKE_SUCCESS object:nil];
}

@end
